package com.lizardmind.haofudoctor.ui.aboutMe.set

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.View
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ActivityChangePasswordBinding
import kotlinx.android.synthetic.main.activity_change_password.*
import org.jetbrains.anko.sdk25.coroutines.onCheckedChange
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by Administrator on 2017/10/27.
 * 修改密码activity
 */
class ChangePasswordActivity: BaseActivity() {

    val fragmentByOld: Fragment=ChangePasswordByOldFragment()
    val fragmentByPhone: Fragment= ChangePasswordByPhoneNumFragment()

    val binding by lazy { getDataBinding<ActivityChangePasswordBinding>(R.layout.activity_change_password) }
    override fun onCreatRootView(): View {
        return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {

        val ft=supportFragmentManager.beginTransaction()
        ft.add(R.id.frameLayout,fragmentByOld)
        ft.add(R.id.frameLayout,fragmentByPhone)
        ft.commitNow()

        showHideFragment(fragmentByOld,fragmentByPhone)

        imgRight.onClick{ finish() }

        cbRight.onCheckedChange{ p0, checked ->
            if (checked){
                showHideFragment(fragmentByOld,fragmentByPhone)
                cbRight.text="短信验证"
            }else{
                showHideFragment(fragmentByPhone,fragmentByOld)
                cbRight.text="旧密码修改"
            }
        }
    }

    private fun showHideFragment(show:Fragment,hide:Fragment){
        val ft=supportFragmentManager.beginTransaction()
        ft.hide(hide)
        ft.show(show)
        ft.commit()
    }
}